package com.cgg.designpatterns.iterator;

import java.util.Iterator;

/**
 * @author Xiecheng create on 2021/6/27
 */
public class BookShelfIterator implements Iterator<Book> {

    /**
     * 需要迭代的书架
     */
    private final BookShelf bookShelf;
    /**
     * 迭代器当前指针
     */
    private int index;

    public BookShelfIterator(BookShelf bookShelf) {
        this.bookShelf = bookShelf;
        this.index = 0;
    }

    @Override
    public boolean hasNext() {
        return this.index < bookShelf.getSize();
    }

    @Override
    public Book next() {
        Book book = this.bookShelf.getBook(index);
        index ++;
        return book;
    }
}
